package TOP101;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

/**
 * @Question BM35
 * @Date 2022/11/21 10:30
 * @Solution
 */
public class BM35 {
    public boolean isCompleteTree (TreeNode root) {
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        boolean isNull = false;
        while(!queue.isEmpty()) {
            int s = queue.size();
            for(int i=0;i<s;i++) {
                TreeNode cur = queue.poll();
                if(isNull==false && cur!=null) {
                    queue.add(cur.left);
                    queue.add(cur.right);
                } else if(isNull==true && cur!=null) {
                    return false;
                }
                if(cur==null) {
                    isNull=true;
                }
            }
        }
        return true;
    }
}
